import React from 'react';
import { Layout,message } from 'antd';
import { Form, Input, Button, Checkbox } from 'antd';
import "./Login.css"
import {inject,observer} from "mobx-react";
import Axios from "./../util/axios"
import {Link} from "react-router-dom";
function Login(props) {
    const { Header, Footer, Content } = Layout;
    //跳转到主页面
    const onFinish = (values) => {
        console.log(values)
        Axios.post('/Login',values).then((res)=>{
            if(res.data.code===200){
                props.user.user=res.data.data
                let juri=res.data.data[0].Juri
                Axios.post('/getjuri',{juri:juri}).then((res1)=>{
                    if(res1){
                        message.success('登录成功');
                        props.user.routerurl=res1.data.data
                        props.history.push('/index')
                    }
                })
            }else {
                console.log(res)
                message.error('账号或密码错误');
            }
        })
    };

    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };
    return (
        <div>
            <Layout className="login">
                <Header className={"header"}>
                    <h1>黄金珠宝进销存系统</h1>
                </Header>
                <Content className={"content"}>
                    <div className={"frmLogin"}>
                        <h2>登录</h2>
                        <Form
                            name="basic"
                            labelCol={{
                                span: 8,
                            }}
                            wrapperCol={{
                                span: 16,
                            }}
                            initialValues={{
                                remember: true,
                            }}
                            onFinish={onFinish}
                            onFinishFailed={onFinishFailed}
                            autoComplete="off"
                        >
                            <Form.Item
                                label="用户名"
                                name="username"
                                rules={[
                                    {
                                        required: true,
                                        message: '请输入用户名!',
                                    },
                                ]}
                            >
                                <Input />
                            </Form.Item>

                            <Form.Item
                                label="密码"
                                name="password"
                                rules={[
                                    {
                                        required: true,
                                        message: '请输入密码!',
                                    },
                                ]}
                            >
                                <Input.Password />
                            </Form.Item>
                            <Form.Item
                                name="remember"
                                valuePropName="checked"
                                wrapperCol={{
                                    offset: 8,
                                    span: 16,
                                }}
                            >
                                <Checkbox>记住密码</Checkbox>
                            </Form.Item>
                            <Form.Item
                                wrapperCol={{
                                    offset: 8,
                                    span: 16,
                                }}
                            >
                                <Button className={"Loginbut"} type="primary" htmlType="submit">
                                    登录
                                </Button>
                                <Button  type="primary" ><Link to={"/reg"}>注册</Link></Button>
                            </Form.Item>
                        </Form>
                    </div>
                </Content>
                <Footer className={"footer"}>
                    <p>
                        copyright 2021.6
                    </p>
                </Footer>
            </Layout>
        </div>
    );

}

export default inject('user')(observer(Login));